package com.base.commonlib.base;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;


import me.yokeyword.fragmentation.SupportFragment;
/**
 * Date：2019/4/9 下午4:23
 * Creator：arvin
 * Des：
 */

public abstract class BaseFragment extends SupportFragment {
    protected Context mContext;
    protected ViewDataBinding mRootBinding;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mContext = getActivity();
        mRootBinding = DataBindingUtil.inflate(inflater, getLayoutResource(), null, false);
        return mRootBinding.getRoot();
    }

    void showMesB(String msg) {
        Activity activity = getActivity();
        ((BaseActivity) activity).showMesB(msg);
    }

    void showMesWActionB(String msg, String action, View.OnClickListener listener) {
        Activity activity = getActivity();
        ((BaseActivity) activity).showMesWActionB(msg, action, listener);
    }


    protected boolean checkTextView(TextView tv) {
        return ((BaseActivity)getActivity()).checkTextView(tv);
    }

    protected boolean checkEditText(EditText et) {
        return ((BaseActivity)getActivity()).checkEditText(et);
    }


    protected boolean checkSpinner(Spinner sp) {
        return ((BaseActivity)getActivity()).checkSpinner(sp);
    }


    protected void customStartActivity(Intent intent) {
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(intent);
    }

    protected void customStartActivityForResult(Intent intent, int requestCode) {
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        super.startActivityForResult(intent, requestCode);
    }

    protected void onLogin(){
        ((BaseActivity)getActivity()).startLogin();
    }

    protected abstract int getLayoutResource();
}
